package com.geniusk.security.config;

import com.geniusk.security.Interceptor.HeaderInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class SecurityConfig implements WebMvcConfigurer {

    // 需要排除的地址
    public static final String[] excludeUrls = {"/app/passport/getCheckImage", "/app/passport/login",
            "/app/passport/getSmsCode", "/app/passport/registerAndLogin",
            "/app/passport/logout", "/app/update/selectLatestApp", "/system/passport/getCheckImage",
            "/system/passport/login", "/system/passport/logout", "/system/app/selectLatestApp",
            "/system/device/firmware/**"};

    @Bean
    public HeaderInterceptor getHeaderInterceptor() {
        return new HeaderInterceptor();
    }

    /**
     * 注册拦截器，并且拦截指定的路由，否则不生效
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(getHeaderInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns(excludeUrls);
    }
}
